package com.mindskip.xzs.repository;

import com.mindskip.xzs.domain.ExamPaperAnswer;
import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.repository.base.MyMapper;
import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface ExamPaperAnswerMapper extends MyMapper<ExamPaperAnswer> {
//    int deleteByPrimaryKey(Integer id);

//    int insert(ExamPaperAnswer record);

//    int insertSelective(ExamPaperAnswer record);

//    ExamPaperAnswer selectByPrimaryKey(Integer id);

//    int updateByPrimaryKeySelective(ExamPaperAnswer record);

//    int updateByPrimaryKey(ExamPaperAnswer record);

    String queryParams = " id, exam_paper_id examPaperId, paper_name paperName, paper_type paperType, subject_id subjectId, system_score systemScore, user_score userScore,\n" +
            "paper_score paperScore, question_correct questionCorrect, question_count questionCount, do_time doTime, status, create_user createUser, create_time createTime,\n" +
            "task_exam_id taskExamId ";

    @Select("SELECT count(*) from t_exam_paper_answer")
    Integer selectAllCount();

    @Select("SELECT create_time as name,COUNT(create_time) as value from\n" +
            "\t\t        (\n" +
            "\t\t\t\t  SELECT DATE_FORMAT(create_time,'%Y-%m-%d') as create_time from t_exam_paper_answer\n" +
            "\t\t\t\t\tWHERE  create_time  between  #{startTime}  and  #{endTime}\n" +
            "\t\t\t\t) a\n" +
            "\t\tGROUP BY create_time")
    List<KeyValue> selectCountByDate(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    @Select("select \n" +
            queryParams +
            " from t_exam_paper_answer\n" +
            "where exam_paper_id = #{pid} and create_user=#{uid}\n" +
            "limit 1")
    ExamPaperAnswer getByPidUid(@Param("pid") Integer paperId, @Param("uid") Integer uid);

    @Select("<script>" +
            " select " +
            queryParams +
            " from t_exam_paper_answer" +
            "<if test=\"subjectId != null\"> and subject_id = #{subjectId} </if>" +
            "</script>")
    List<ExamPaperAnswer> adminPage(@Param("subjectId") Integer subjectId);
}
